<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CORS</title>
</head>
<!-- CROS跨域资源共享，完全的服务端处理，支持get和post请求 -->

<body>
    <button>点击发送请求</button>
</body>
<script>
    const btn = document.querySelector('button');
    btn.onclick = function() {
        let x = new XMLHttpRequest();
        x.open('GET', 'http://127.0.0.1:8000/cors');
        x.send();
        x.onreadystatechange = function(data) {
            if (x.readyState === 4) {
                if (x.status >= 200 && x.status < 300) {
                    console.log(data);
                }
            }
        }
    }
</script>

</html>